package com.lhc.nacosprovider;

import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;

import java.nio.charset.StandardCharsets;

/**
 * @author liuchaoqun
 * @date 2022/7/1
 * @Description MQ测试
 */
public class SendMessage {
    public static void main(String[] args) throws MQClientException, MQBrokerException, RemotingException, InterruptedException {
        // 创建生产者，设置生产者组名
        DefaultMQProducer test = new DefaultMQProducer("test");
        // 设置NameSer地址
        test.setNamesrvAddr("101.201.150.42:9876");
        // 启动生产者

        test.start();
        // 构建消息对象

        Message message = new Message("topicA", "myTag", ("one Test").getBytes(StandardCharsets.UTF_8));
        // 发送消息,超时时间
        SendResult result = test.send(message, 10000);
        System.out.println(result);

        // 关闭生产者
        test.shutdown();

    }
}
